﻿@{
    ViewBag.Title = "NSRWQWQYYL";
    Layout = "~/Views/Shared/_LayoutChild.cshtml";
}
@section head {
    @if (false)
    {<script src="~/Scripts/jquery-1.6.4-vsdoc.js" type="text/javascript"></script>}
    @Html.Partial("_JqGrid")
    <script type="text/javascript"
     src="@Url.Content("~/Scripts/jquery.uploadify-3.1.js")"  ></script>
    <link href="@Url.Content("~/Content/uploadify/uploadify.css")"     rel="stylesheet" type="text/css" />
    <style type="text/css">
        table, table td, table th
        {
            border-collapse: collapse;
            font-size: 12px;
        }
        table
        {
            table-layout: fixed;
        }
        td
        {
            white-space: nowrap;
            display: table-cell;
            vertical-align: inherit;
        }
        .uploadify
        {
            margin-top: 4px;
            padding-top: 3px;
            padding-bottom: 0px;
            margin-bottom: 0px;
            border: #ccc 1px solid;
        }
        .uploadify-button
        {
            background-color: transparent;
            border: none;
            padding: 0;
        }
        .uploadify:hover .uploadify-button
        {
            background-color: transparent;
            border: none;
            padding: 0;
            margin-top: -6px;
        }
        .uploadbtn
        {
            width: 40px;
            height: 20px;
            background-color: transparent;
            border: none;
            padding: 0;
        }
        .uploadify-queue
        {
            left: 1px;
            top: 1px;
            width: 40px;
        }
    </style>
    <script language="javascript" type="text/javascript">
        var selectId = "";
        var gridId = "#tableId";
        var edittype = '@ViewBag.edittype'; //0不可编辑，1可编辑
        var colModels = "";
        var saveUrl = '/DataManage/Report/SaveXXNYQYJB/';
        var organization_type = '@ViewBag.Organization.Organization_Type';
        var organization_name = '@ViewBag.Organization.Organization_Name';
        $(document).ready(function () {
            funGridInit();
            colModels = JSON.stringify($(gridId).getGridParam('colModel'));
            initUpload();
            if (edittype == "0") {
                $("#btnImport").css('display', 'none');
                $("#addRow").css('display', 'none');
                $("#delRow").css('display', 'none');
                $("#funSave").css('display', 'none');
            }
            //如果是龙头企业，则不能手动添加行，系统将自动为其添加一行
            if (organization_type == '1') {
                $("#addRow").css('display', 'none');
                $("#delRow").css('display', 'none');
            }

        });
        function initUpload() {
            $("#btnImport").uploadify({
                'formData': { 'ASPSESSID': '@(Session.SessionID)', 'AUTHID': '@ViewBag.auth', GUID: '@ViewBag.GUID', 'submitInfoId': '@ViewBag.SubmitInfoId', 'colModels': colModels },
                'multi': false,
                'auto': true,
                'swf': '/Content/uploadify/uploadify.swf',
                'uploader': '/DataManage/Report/importReportExA',
                'width': 60,
                'fileTypeExts': '*.xls',
                'height': 22,
                'buttonImage': '/Content/import.png',
                'onSelect': function (e, queueId, fileObj) { parent.$.cover(true); }, //选择文件后触发的事件。
                'onUploadSuccess': function (file, data, response) {
                    var d = $.parseJSON(data);
                    if (d.ErrorMessage == null || d.ErrorMessage.length == 0) {
//                        $(gridId).clearGridData(); //清空表中原有数据。
                        var thegrid = $(gridId)[0];
                        thegrid.addJSONData(d); //将数据填充到grid中
                        //如果是龙头企业导入，则只能导入一行数据。
                        if (organization_type == '1' && $(gridId).jqGrid('getGridParam', 'reccount') > 1) {
                            top.asyncbox.alert('龙头企业只允许导入一行数据!', '提示');
                            Search(); //重新加载grid
                            parent.$.cover(false);
                            return;
                        }

                        //保存一下数据
                        $.funDetailSave('formDetail', gridId, saveUrl, function (d) {
                            parent.$.cover(false);
                            if (d == null || d.ErrorMessage.length == 0) {
                                // top.asyncbox.tips('导入数据成功!', 'success');//注释掉该行的原因是，funDetailSave里面已经有提示，故此处不需要再提示
                            }
                            else
                                top.asyncbox.alert('导入数据失败!', '提示');
                        });

                    }
                    else {
                        parent.$.cover(false);
                        top.asyncbox.alert('导入数据失败,失败原因：' + d.ErrorMessage, '提示');
                    }
                }
            });
        }

        function Search() {
            //查询
            $(gridId).setGridParam({ page: 1 });
            $(gridId).trigger("reloadGrid");
        }
        function funGridInit() {
            //初始化表格
            var option = {
                height: $("#divGridContainer").height() - 71,
                width: $("#divGridContainer").width() - 3,
                url: '/DataManage/Report/XXNYQYJB_GetList/@ViewBag.SubmitInfoID',
                autowidth: false,
                multiselect: true,
                rowNum: 1000,
                cellEdit: true,
                cellsubmit: 'clientArray',
                datatype: "json",
                sortname: 'SubmitInfoID',
                sortorder: 'desc',
                shrinkToFit: false,
                sortable: false,
                colModel: [
                    { label: '单位', name: 'CompanyName', notnull: true, width: 200, align: 'left', editable: true, edittype: 'text' },
                    { label: '从业人员（人）', name: 'CYRY', width: 100, align: 'right', formatter: 'intFmatter', editable: true, edittype: 'text' },
                    { label: '接待游客（万人次）', name: 'JDYKRS', width: 130, align: 'right', formatter: 'intFmatter', editable: true, edittype: 'text' },
                    { label: '客房月平均入住率（%）', name: 'KFPJRZL', width: 140, align: "right", formatter: 'snNumber', editable: true, edittype: 'text' },
                    { label: '经营总收入（万元）', name: 'JYZSR', width: 130, align: "right", formatter: 'snNumber', editable: true, edittype: 'text' },
                    { label: '经营收入（万元）', name: 'NCPJYSR', width: 130, align: "right", formatter: 'snNumber', editable: true, edittype: 'text' },
                    { label: '水果（吨）', name: 'SGXL', width: 100, align: "right", formatter: 'snNumber', editable: true, edittype: 'text' },
                    { label: '蔬菜（吨）', name: 'SCXL', width: 100, align: "right", formatter: 'snNumber', editable: true, edittype: 'text' },
                    { label: '畜禽（吨）', name: 'CQXL', width: 100, align: "right", formatter: 'snNumber', editable: true, edittype: 'text' },
                    { label: '禽蛋（吨）', name: 'QDXL', width: 100, align: "right", formatter: 'snNumber', editable: true, edittype: 'text' },
                    { label: '水产品（吨）', name: 'SCPXL', width: 100, align: "right", formatter: 'snNumber', editable: true, edittype: 'text' },
                    { label: '基地面积（亩）', name: 'JDMJ', width: 100, align: "right", formatter: 'snNumber', editable: true, edittype: 'text' },
                    { name: 'SubmitInfoID', formatter: 'snNumber', hidden: true }
   	        ],
                onSelectRow: function (rowid, cellname, value, iRow, iCol) {
                    _rowId = rowid;
                },
                ondblClickRow: function (rowid) {
                    _rowId = rowid;
                },
                afterSaveCell: function (rowid, cellname, value, iRow, iCol, flag) {
                    $.goToNextCell(gridId, iRow, iCol, false);
                },
                beforeRequest: function (d) {
                },
                gridComplete: function () {
                    //如果是龙头企业,并且没有录入过数据 ，则自动插入一行,并将企业
                    if (organization_type == '1' && edittype=='1' && $(gridId).jqGrid('getGridParam', 'reccount') == 0) {
                        addRow();
                        $(gridId).setCell(1, "CompanyName", organization_name);
                    }
                }
            };
            var o = jqGridHelper.getConfig("#pageId", option);
            $(gridId).jqGrid(o);
            $(gridId).jqGrid('setGroupHeaders', {
                useColSpanStyle: true,
                groupHeaders: [
	            { startColumnName: 'NCPJYSR', numberOfColumns: 6, titleText: '农产品经营收入及消费、销售量' }
                ]
            });
        }

        function loadGrid() {
            $(gridId).trigger("reloadGrid");
        }

        function funSave() {
            $.funDetailSave('formDetail', gridId, saveUrl, function (d) {
            });
        }

        function addRow() {
        
            var _rownum = $(gridId).getDataIDs().length + 1;
            var _data = { SubmitInfoID: '@ViewBag.SubmitInfoID' };
            $(gridId).addRowData(_rownum, _data);
        }

        function delRow() {
            jqGridHelper.delSelRows(gridId);
        }

        function ExportReport() {
            window.location.href = '/DataManage/Report/ExportXXNYQYJB/@ViewBag.SubmitInfoID';
        }
    </script>
}
<div class="ui-layout-north" id='toolbar'>
    <div id="titlediv" class="headertitle">
    </div>
    <div style="float: right; margin-right: 20px; margin-top: 2px; line-height: 32px;">
        <div style="float: left;">
            <input type="file" name="btnImport" id="btnImport" class=" padding-top: 10px;" />
        </div>
        <div style="float: right;">
            <a onclick="addRow();" class="button green" id="addRow"><span class="icon-botton"
                style="background: url('/Content/16/hj.png') no-repeat scroll 0px 4px;"></span>新增</a>&nbsp;<a
                    onclick="delRow();" class="button green" id="delRow"><span class="icon-botton" style="background: url('/Content/16/hj.png') no-repeat scroll 0px 4px;"></span>删除</a>&nbsp;
            <a onclick="funSave();" class="button green" id="funSave"><span class="icon-botton"
                style="background: url('/Content/16/hj.png') no-repeat scroll 0px 4px;"></span>保存</a>
            <a onclick="ExportReport();" class="button green"><span class="icon-botton" style="background: url('/Content/16/hj.png') no-repeat scroll 0px 4px;">
            </span>导出</a>
        </div>
    </div>
</div>
<div id="divGridContainer" class="ui-layout-center" style="overflow: hidden;">
    <form id="formData" method="post">
    </form>
    <table id="tableId">
    </table>
    <div id="pageId">
    </div>
</div>
